package chapter.third.item8;

import java.awt.Color;

/**  
 * 复合优先于继承
 * @author lzy
 *
 */
public class ColorPoint2 {
	private final Point point;
	
	private final Color color;
	
	public ColorPoint2(int x,int y,Color color){
		if(color==null){
			throw new NullPointerException();
		}
		this.point = new Point(x,y);
		this.color = color;
	}

	/**
	 * 完美遵守equals规则
	 */
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof ColorPoint2)){
			return false;
		}
		ColorPoint2 cp = (ColorPoint2)obj;
		return cp.point.equals(point)&&cp.color == color;
	}
	
}
